package com.log.controller;

import com.log.common.vo.ResultVo;
import com.log.pojo.LogCar;
import com.log.service.LogCarService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
*
* @author 王泽旺
* @date 2023/10/20
*/
@RestController
@Api(tags = "车辆管理",value = "车辆的增删改查，运用了RESTful接口规范")
@CrossOrigin //允许跨域请求
@RequestMapping("/car")
public class LogCarController {
    @Autowired
    private LogCarService logCarService;

    /**
     * 添加车辆信息
     * @param logCar
     * @return
     */
    @ApiOperation("添加车辆信息接口")
    @PostMapping("/addCarInfo")
    public ResultVo addCarInfo(@RequestBody LogCar logCar){

        return logCarService.insertCarInfo(logCar);
    }

    /**
     * 通过id查询某辆车信息接口
     * @param id
     * @return
     */
    @ApiOperation("通过id查询某辆车信息接口")
    @GetMapping("/{id}")
    public ResultVo getCarInfo(@PathVariable("id") int id){
        return logCarService.getCarInfoById(id);
    }

    /**
     * 更新车辆信息接口
     * @param logCar
     * @return
     */
    @ApiOperation("更新车辆信息接口")
    @PostMapping("/updateCarInfo")
    public ResultVo updateCarInfo(@RequestBody LogCar logCar){
        return logCarService.updateCarInfo(logCar);
    }

    /**
     * 分页查询全部车辆接口
     * @param pageNum
     * @param limit
     * @return
     */
    @ApiOperation("分页查询全部车辆接口")
    @GetMapping("/getCarsPage")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(dataType = "int",name = "pageNum",value = "当前的页码",required = true),
                    @ApiImplicitParam(dataType = "int",name = "limit",value = "每页显示条数",required = true),

            }
    )
    public ResultVo getCarsPage(int pageNum,int limit){
        return logCarService.getAllCarInfoByPage(pageNum,limit);
    }

    /**
     * 通过不同状态分页查询车辆接口
     * @param pageNum
     * @param limit
     * @param status
     * @return
     */
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(dataType = "int",name = "pageNum",value = "当前的页码",required = true),
                    @ApiImplicitParam(dataType = "int",name = "limit",value = "每页显示条数",required = true),

            }
    )
    @ApiOperation("通过不同状态分页查询车辆接口")
    @GetMapping("/getCarsPageByStatus")
    public ResultVo getCarsPageByStatus(int pageNum,int limit,int status){
        return logCarService.getAllCarInfoByPageAndStatus(pageNum,limit,status);
    }



}
